package org.nanfang.synchronization;

/**
 * @author ZQX
 * @date 2025-03-12
 */
public class MyRunnable implements Runnable {
    /**
     * 电影票 - 50张
     */
    private int ticket = 50;
    //常量
    private String lock = "";
    @Override
    public void run() {
        while (true) {
        synchronized (lock){
                if (ticket <= 0) {
                    break;
                }
                String name = Thread.currentThread().getName();
                System.out.printf("票价售出了10%", name, ticket);
                ticket--;
            }
        }
    }
}
